package com.anan.controller;

import com.anan.annotation.CheckObject;
import com.anan.annotation.GlobalInterceptor;
import com.anan.entity.po.UserFileInfo;
import com.anan.entity.query.UserFileInfoQuery;
import com.anan.service.UserFileInfoService;
import com.anan.utils.Result;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/user_file_info")
public class UserFileInfoController {

    @Resource
    UserFileInfoService userFileInfoService;


    @RequestMapping("/add")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result add(@CheckObject(required = true, checkProperties = {"userId","fileName","fileType","alterTime"}) @RequestBody UserFileInfo userFileInfo) {
        Result result = new Result();
        UserFileInfo userFileInfo1 = userFileInfoService.insertb(userFileInfo);
        if(userFileInfo1 != null){
            result.setCode(200);
            result.setMsg("文档添加成功");
            result.setData(userFileInfo1);
        }else{
            result.setCode(400);
            result.setMsg("文档添加失败");
            result.setData(null);
        }

        return result;
    }

    @RequestMapping("/delete")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result delete(@CheckObject(required = true, checkProperties = {"all"}) @RequestBody UserFileInfo userFileInfo) {
        Result result = new Result();

        return result;
    }

    @RequestMapping("/update")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result update(@CheckObject(required = true, checkProperties = {"all"}) @RequestBody UserFileInfo userFileInfo) {
        Result result = new Result();

        return result;
    }

    @RequestMapping("/get")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result get(@CheckObject(required = true, checkProperties = {"all"}) @RequestBody UserFileInfo userFileInfo) {
        Result result = new Result();
        return result;
    }

    @RequestMapping("/list")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result list(HttpServletRequest request,
                       @CheckObject(required = true, checkProperties = {"userId"}) @RequestBody UserFileInfoQuery userFileInfo) {
        Result result = new Result();
        List<UserFileInfo> list = userFileInfoService.list(userFileInfo);
        result.setCode(200);
        result.setMsg("获取所有文档信息成功");
        result.setData(list);

        return result;
    }

    @RequestMapping("/listB")
    @GlobalInterceptor(checkParams = true, checkLogin = true)
    public Result listB(@CheckObject(required = true, checkProperties = {"all"}) @RequestBody UserFileInfo userFileInfo,
                        @CheckObject(required = true, checkProperties = {"all"}) @RequestBody List<UserFileInfo> list) {
        Result result = new Result();
        return result;
    }
}
